/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import BaseDatos.Conexion;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author JEANPIERE
 */
public class RegistroAlumnos {
    
    
    public static Alumno buscarAlumno(String codigo,String password){
        Conexion con = new Conexion();
         Connection cn;
          cn = con.conectar();
        Alumno alumno =null;
        
        try
        {
            String sql = "SELECT * FROM alumno WHERE codigo = ? AND contraseña=? ";
            PreparedStatement cmd = cn.prepareStatement(sql);
            cmd.setString(1, codigo);
            cmd.setString(2, password);
            ResultSet rs = cmd.executeQuery();
            if(rs.next())
            {
                Alumno alu = new Alumno();
                alu.setCodigo(rs.getString(1));
                alu.setNombre(rs.getString(2));
                alu.setApellidos(rs.getString(3));
                alu.setDni(rs.getInt(4));
                alu.setCodProfesor(rs.getString(5));
                alu.setContraseña(rs.getString(6));
                alumno=alu;
            }
            cmd.close();
            cn.close();
        }
        catch(Exception ex)
        {
            System.out.println("Error: " + ex.getMessage());
        }
        return alumno;
        
        
    }
}
